package RedBag;

import java.lang.reflect.Member;
import java.util.ArrayList;
import java.util.Random;

public class Player {
    private String name;
    private int money;
    public Player(String name, int money) {
        this.name = name;
        this.money = money;
    }
    public String getName() {
        return name;
    }
    public int getMoney() {
        return money;
    }
    public void setMoney(int money) {
        this.money = money;
    }
    public void setName(int amount) {
        this.name = String.valueOf(amount);
    }

    public void show(){
        System.out.println("我叫"+name+"发了"+money+"钱");
    }
    public ArrayList<Integer> send(int totalMoney, int count) {
        ArrayList<Integer> RedList = new ArrayList<>();
        int leftMoney = this.getMoney();
        if(totalMoney > leftMoney){
            System.out.println("余额不足");
        }
        this.setMoney(leftMoney - totalMoney);
        Random random = new Random();
        int AnyNum = random.nextInt(leftMoney)+1;

        for(int i = 0; i<count-1; i++){
            AnyNum = random.nextInt(leftMoney)+1;
            RedList.add(AnyNum);
            leftMoney -= AnyNum;
        }
        RedList.add(leftMoney);
        return RedList;
    }
    public void receive(ArrayList<Integer> list) {
        int index = new Random().nextInt(list.size());
        Integer delta = list.remove(index);
        this.setMoney(this.getMoney() + delta);
    }
}
